package com.problem.leetcode;

/**
 * 解题思路:利用题目的特性，找到最大和最小的数字，然后再减去2*K
 * @author didi
 * @DESCRIPTION
 * @create 2019-05-20 19:43
 **/

public class Problem908 {
    public int smallestRangeI(int[] A, int K) {
        int max = 0, min = 10000;
        for (int index = 0; index < A.length; index++) {
            if (A[index] < min) {
                min = A[index];
            }
            if (A[index] > max) {
                max = A[index];
            }
        }

        int result = max - min - 2 * K;
        return result < 0 ? 0 : result;

    }
}
